package four;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @Auther     : yxpweb
 * @Date       : 2021/7/3 9:24
 * @Description: 和Runnable的主要区别：1、可抛出异常2、返回3、方法调用
 */
public class FutureTaskTest3 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Task3 task3 = new Task3();
        FutureTask<Integer> futureTask = new FutureTask(task3);
        new Thread(futureTask, "A").run();
        new Thread(futureTask, "B").run(); // 结果只会执行一次，结果是有缓存的，
        Integer o = futureTask.get();// 这个地方可能会有阻塞
        System.out.println(o);
    }

}

class Task3 implements Callable<Integer> {

    @Override
    public Integer call() {
        System.out.println("call");
        return 886;
    }
}
